<%-- 
    Document   : locale
    Created on : 16-feb-2012, 9.35.14
    Author     : Ivan
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <script src="JS/style.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
        <link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
        <script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Pagina Locale</title>
    </head>
    <body>
        <%@include file="header.jsp" %>
        <div id="content">
            <%
                String[] ris = (String[]) session.getAttribute("risultato");
                List<String[]> elencoEventi = null;
                if (session.getAttribute("login") != null && session.getAttribute("group").equals("locale")) {
                    elencoEventi = (List<String[]>) session.getAttribute("elencoEventi");
                }
                List<String[]> rec = (List<String[]>) session.getAttribute("recensioni");
                float val = 0;
                for (int i = 0; i < rec.size(); i++) {
                    String[] temp = rec.get(i);
                    val += Integer.parseInt(temp[3]);
                }
                if (rec.size() != 0) {
                    val /= rec.size();
                    val *= 10;
                    val = Math.round(val);
                    val /= 10;
                } else {
                    val = 3;
                }
                int k = Math.round(val);

                int j;
            %>
            <div id="imgLocale">
                <fieldset>
                <img id="immagine" src="<%= ris[8]%>"  class="img"/>
                </fieldset>
            </div>
            <div id="description">
                <fieldset  class="title">
                    <p id="pubName"><%= ris[0]%></p>
                    <p id="pubProp">di <%= ris[9]%></p>
                    <p id="valutazione">
                        <%
                            for (j = 0; j < k; j++) {
                        %>
                        <img src="img/star-on.gif" alt="star-on.gif"/>
                        <%                    }
                            for (int h = j; h < 5; h++) {
                        %>
                        <img src="img/star-off.gif" alt="star-off.gif"/>
                        <%                    }
                        %>

                        (<%=val%> / 5)
                    </p>
                </fieldset>
                <div id="info">
                    <fieldset>
                        <%@ page import="org.netbeans.saas.*, org.netbeans.saas.google.*" %>
                        <%
                            try {
                                java.lang.Integer zoom = 15;
                                String iframe = "false";
                                RestResponse result = GoogleMapService.getGoogleMap(ris[3], zoom, iframe);
                                out.println(result.getDataAsString());
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        %>
                        <legend>Informazioni Utili</legend>
                        <button type="button" name="home" value="home" class="css3button4">Indirizzo:</button> <%=ris[3]%><br />
                        <button type="button" name="home" value="home" class="css3button4">E-mail:</button> <%=ris[2]%><br />
                        <button type="button" name="home" value="home" class="css3button4">Telefono:</button> <%= ris[5]%><br />
                        <button type="button" name="home" value="home" class="css3button4">P. IVA:</button> <%= ris[7]%><br />
                        <button type="button" name="home" value="home" class="css3button4">Numero Posti:</button> <%=ris[4]%><br />
                        <button type="button" name="home" value="home" class="css3button4">Orario:</button> <%=ris[6]%><br />
                        <%if (session.getAttribute("login") != null && session.getAttribute("login").equals(ris[0]) && session.getAttribute("group").equals("locale")) {%>
                        <a href="/EsameSSCSWeb-war/download/ClientLocali.jar"><button type="button" name="home" value="home" class="css3button6">Download dell'applicazione</button></a>
                        <%}%>
                    </fieldset>
                </div>
                <div id="descLocale">
                    <fieldset>
                        <legend>Descrizione Locale</legend>
                        <p><%=ris[1]%></p>
                    </fieldset>
                    <%
                        if (session.getAttribute("login") != null && session.getAttribute("group").equals("locale") && session.getAttribute("login").equals(ris[0])) {
                    %>
                    <div id="eventiCreati">
                        <fieldset>
                            <legend>Elenco Eventi Organizzati</legend>

                            <a href="/EsameSSCSWeb-war/Servlet?action=creaEvento"><button type="button" name="login" value="newEvent" class="css3button5">Crea un nuovo evento</button></a>

                            <% if (elencoEventi != null && elencoEventi.size() == 0) {%>     
                            Non ci sono eventi organizzati
                            <%} else {%>
                            <table class="prenotazioni">
                                <tr>
                                    <th>Immagine</th>
                                    <th>Nome evento</th>
                                    <th>Data evento</th>
                                    <th>Numero di posti disponibili</th>
                                    <th></th>
                                </tr>
                                <% for (int i = 0; i < elencoEventi.size(); i++) {%>
                                <tr>
                                    <td>
                                        <img width="100" src="<%=elencoEventi.get(i)[3]%>"/>
                                    </td>
                                    <td>
                                        <a href="/EsameSSCSWeb-war/Servlet?action=evento&nome=<%=elencoEventi.get(i)[0]%>"><%=elencoEventi.get(i)[0]%></a>
                                    </td>
                                    <td>
                                        <%=elencoEventi.get(i)[1]%>
                                    </td>
                                    <td>
                                        <%=elencoEventi.get(i)[4]%>
                                    </td>
                                    <td>
                                        <a href="/EsameSSCSWeb-war/Servlet?action=cancellaEvento&nome=<%=elencoEventi.get(i)[0]%>">
                                            <button type="button" name="cancellaEvento" value="cancelEvent" class="css3button">Cancella</button>
                                        </a>
                                    </td>
                                </tr>
                                <%}%>
                            </table>
                            <%}%>
                        </fieldset>
                    </div>
                    <%}%>

                    <%
                        if (session.getAttribute("login") != null && session.getAttribute("group").equals("cliente")) {
                    %>
                    <form action="/EsameSSCSWeb-war/Servlet?action=prenota&nome=<%= ris[0]%>&tipo=locale" method="post">
                        <fieldset>
                            <legend>
                                Prenotazione
                            </legend>
                            <table border="0">
                                <tr>
                                    <td>
                                        Numero di posti:
                                    </td>
                                    <td>
                                        <input type="text" name="numposti"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Data:
                                    </td>
                                    <td>
                                        <input type="text" name="data" id="inputField" />
                                    </td>
                                </tr>
                            </table>
                            <p>
                                <button id="submit" type="submit">Prenota <img src="img/ok.gif" alt="ok"/></button>
                                <button type="reset">Cancella <img src="img/cancel.gif" alt="cancel"/></button>
                            </p>
                        </fieldset>
                    </form>
                    <form action="/EsameSSCSWeb-war/Servlet?action=recensione&nome=<%= ris[0]%>" method="post">
                        <fieldset>
                            <legend>
                                Inserisci recensione
                            </legend>
                            <table border="0">
                                <tr>
                                    <td>
                                        Commento:
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <textarea name="dettagli" rows="5" cols="40">Qui puoi scrivere la tua recensione</textarea>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Valutazione
                                    </td>
                                    <td>
                                        <select name="valutazione">
                                            <option value="0">0</option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3" selected="selected">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                            <p>
                                <button id="submit" type="submit">Invia commento <img src="img/ok.gif" alt="ok"/></button>
                                <button type="reset">Cancella <img src="img/cancel.gif" alt="cancel"/></button>
                            </p>
                        </fieldset>
                    </form>
                    <%}%>
                    <fieldset>
                        <legend>
                            Recensioni
                        </legend>
                        <%
                            for (int i = 0; i < rec.size(); i++) {
                                String[] temp = rec.get(i);
                        %>
                        <p>
                            <%=temp[2]%> (<%=temp[0]%>)
                            <br/>
                            <%
                                k = Math.round(Integer.parseInt(temp[3]));
                                for (j = 0; j < k; j++) {
                            %>
                            <img src="img/star-on.gif" alt="star-on.gif"/>
                            <%                    }
                                for (int h = j; h < 5; h++) {
                            %>
                            <img src="img/star-off.gif" alt="star-off.gif"/>
                            <%                    }
                            %>

                            (<%=temp[3]%> / 5)
                            <br/>
                            <%=temp[1]%>
                        </p>
                        <% }%>
                        </table>
                    </fieldset>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        window.onload = function()
        {
            sottobarra=document.getElementById("subbar1");  
            cerca=document.getElementById("cerca");
            sottobarra2=document.getElementById("subbar2");  
            sottobarra3=document.getElementById("subbar3");  
            login=document.getElementById("login");
            cerca.style.display="none";
            sottobarra.style.display="none";
            login.style.display="none";
            if(sottobarra2!=null)
                sottobarra2.style.display="none";
            else
                sottobarra3.style.display="none";
        <%if (session.getAttribute("login") != null && session.getAttribute("group").equals("cliente")) {%>
                new JsDatePick({
                    useMode:2,
                    target:"inputField",
                    dateFormat:"%d/%m/%Y"
			
                });
        <%}%>
                
                loadScript();
            }
    </script>
</html>
